/**
 * 用户api
 */
import { GetRequestApi, PostRequestApi, PutRequestApi } from '@/utils/api/RequestApi'

export const USER_API_PRE_SUFFER = '/user/'
import { role, user, userLogin } from '../../entity/system/user'

/**
 * 登录
 * @param data
 */
export function login(data: userLogin) {
  return new PostRequestApi<user>('login', data).get()
}

/**
 * 注册
 * @param data
 */
export function registry(data: user) {
  return new PostRequestApi<user>('register', data).get()
}

/**
 * 获取验证码
 */
export function captcha() {
  return new GetRequestApi(
    'captcha.jpg',
    {},
    {
      responseType: 'blob',
    },
  ).get()
}

/**
 * 获取用户信息
 * @param name
 */
export function getUserByName(name: string) {
  return new GetRequestApi<user>(USER_API_PRE_SUFFER + 'findByName', {
    name: name,
  }).get()
}

/**
 * 获取权限信息
 * @param name
 */
export function getPermissionByName(name: string) {
  return new GetRequestApi<Array<string>>(USER_API_PRE_SUFFER + 'findPermissions', { name: name }).get()
}

/**
 * 获取角色信息
 * @param id
 */
export function getRoleById(id: string) {
  return new GetRequestApi<Array<role>>(USER_API_PRE_SUFFER + 'findUserRoles/' + id).get()
}

/**
 * 新增用户
 */
export function add(data: user) {
  return new PostRequestApi(USER_API_PRE_SUFFER, data).get()
}

/**
 * 修改用户
 */
export function update(data: user) {
  return new PutRequestApi(USER_API_PRE_SUFFER, data).get()
}
